package edu.hawaii.senin.iclouds.simple;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import edu.hawaii.senin.iclouds.basics.Reaction;
import edu.hawaii.senin.iclouds.basics.ReadConfigException;

/**
 * Tests appropriate coniguration parsing.
 * 
 * @author Pavel Senin.
 * 
 */
public class TestReactionSetup {

  private static final String configName1 = "config/test_cfg/test002.xml";
  private Cloud testCloud;

  /**
   * Makes setup fixture.
   * 
   * @throws ReadConfigException if an error encountered.
   * 
   */
  @Before
  public void setUp() throws ReadConfigException {
    this.testCloud = new Cloud();
    CloudParametersMessage cm = new CloudParametersMessage();
    cm.addParameter(CloudParametersMessage.CFGNAME, configName1);
    testCloud.setParameters(cm);
  }

  /**
   * Tests correct variables extraction and barrier calculation.
   * 
   */
  @Test
  public void testHDFReactionsSetup() {

    CloudReactions cr = testCloud.getcloudReactions();

    // Atom Reactant Product Barrier
    // H C CH 15345617920
    Reaction r = cr.get("HCH_CH2");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10, r.getChi());
    // H CH CH2 15345617920
    r = cr.get("HCH2_CH3");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H CH2 CH3 15345617920
    r = cr.get("HCH2_CH3");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H CH3 CH4 15345617920
    r = cr.get("HCH3_CH4");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H CH3O CH3OH 15345617920
    r = cr.get("HCH3O_CH3OH");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H CN HCN 15345617920
    r = cr.get("HCN_HCN");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H CO HCO 2522471
    r = cr.get("HCO_HCO");
    assertEquals("Testeing reaction Chi", 2532458.9104352077D, r.getChi());
    // H H2CO CH3O 2522471
    r = cr.get("HH2CO_CH3O");
    assertEquals("Testeing reaction Chi", 2532458.9104352077D, r.getChi());
    // H H2CO H2COH 2522471
    r = cr.get("HH2CO_H2COH");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 2532458.9104352077D, r.getChi());
    }
    // H H2COH CH3OH 15345617920
    r = cr.get("HH2COH_CH3OH");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }
    // H H2O2 H2O 237766
    r = cr.get("HH2O2_H2O");
    assertEquals("Testeing reaction Chi", 238881.2572510605, r.getChi());
    // H HCO H2CO 15345617920
    r = cr.get("HHCO_H2CO");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H HCOO HCOOH 15345617920
    r = cr.get("HHCOO_HCOOH");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H HO2 H2O2 15345617920
    r = cr.get("HHO2_H2O2");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H N NH 15345617920
    r = cr.get("HN_NH");
    assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    // H N2H N2H2 15345617920
    r = cr.get("HHN2H_N2H2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }
    // H N2H2 N2H 30662534
    r = cr.get("HN2H2_N2H");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 3.0760376105423395E7D, r.getChi());
    }
    // H NH NH2 15345617920
    r = cr.get("HNH_NH2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }
    // H NH2 NH3 15345617920
    r = cr.get("HNH2_NH3");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

    // H NH2CO NH2CHO 15345617920
    r = cr.get("HNH2CO_NH2CHO");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

    // H NHCO NH2CO 15345617920
    r = cr.get("HNHCO_NH2CO");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

    // H NO HNO 15345617920
    r = cr.get("HNO_HNO");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

    // H NO2 HNO2 15345617920
    r = cr.get("HNO2_HNO2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

    // H NO3 HNO3 15345617920
    r = cr.get("HNO3_HNO3");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

    // H O OH 15345617920
    r = cr.get("HO_OH");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }
    // H O2 HO2 737068
    r = cr.get("HO2_HO2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 740266.1126555692D, r.getChi());
    }
    // H O3 O2 175643008
    r = cr.get("HO3_O2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.7610922952592462E8D, r.getChi());
    }
    // H OCN HNCO 15345617920
    r = cr.get("HOCN_HNCO");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 1.5365279891281485E10D, r.getChi());
    }

  }

  /**
   * Tests correct variables extraction and barrier calculation.
   * 
   */
  @Test
  public void testCReactionsSetup() {

    CloudReactions cr = testCloud.getcloudReactions();

    // Atom Reactant Product Barrier
    // C N CN 37.7513
    Reaction r = cr.get("CN_CN");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
  }

  /**
   * Tests correct variables extraction and barrier calculation.
   * 
   */
  @Test
  public void testOReactionsSetup() {
    CloudReactions cr = testCloud.getcloudReactions();

    // Atom Reactant Product Barrier
    // Atom Reactant Product Barrier
    // O CN OCN 37.7513
    Reaction r = cr.get("OCN_OCN");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    // O CO CO2 37.7513
    r = cr.get("OCO_CO2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    }
    // O HCO HCOO 37.7513
    r = cr.get("OHCO_HCOO");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    // O N NO 37.7513
    r = cr.get("ON_NO");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    // O NO NO2 37.7513
    r = cr.get("ONO_NO2");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    // O NO2 NO3 37.7513
    r = cr.get("ONO2_NO3");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    // O O O2 37.7513
    r = cr.get("OO_O2");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    // O O2 O3 37.7513
    r = cr.get("OO2_O3");
    assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
  }

  /**
   * Tests correct variables extraction and barrier calculation.
   * 
   */
  @Test
  public void testNReactionsSetup() {
    CloudReactions cr = testCloud.getcloudReactions();

    // Atom Reactant Product Barrier
    // N C CN 37.7513
    Reaction r = cr.get("NC_CN");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    }
    // N HCO NHCO 37.7513
    r = cr.get("NHCO_NHCO");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    }
    // N N N2 37.7513
    r = cr.get("NN_N2");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    }
    // N NH N2H 37.7513
    r = cr.get("NNH_N2H");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    }
    // N O NO 37.7513
    r = cr.get("NO_NO");
    if (null != r) {
      assertEquals("Testeing reaction Chi", 37.75134544279098D, r.getChi());
    }
  }

}
